package map;

import java.util.*;

public class MapDemo2 {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("语文",100);
        map.put("数学",56);
        map.put("英语",66);
        map.put("物理",85);
        map.put("化学",94);

        Set<String> keySet = map.keySet();//获取key
        for (String key : keySet){
            System.out.println(key);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();//获取键值对
        for (Map.Entry<String,Integer> e: entrySet){
            String key  = e.getKey();
            Integer value = e.getValue();
            System.out.println(key+":"+value);
        }

        //map的foreach方法
        map.forEach(
                (key,value)-> System.out.println(key+":"+value)
        );

        Collection<Integer> values = map.values();
//        for (Integer value: values){
//            System.out.println("value:"+value);
//        }
        values.forEach(
                value-> System.out.println("value:"+value)
        );
    }
}
